package com.hooker.mail;

public class SendMailUtil {
    //qq
    private static final String HOST = "mail.jkohjkng.top";
    private static final String PORT = "25";
    private static final String FROM_USER = "penetration.analysis"; //发送方邮箱
    private static final String FROM_ADD = "penetration.analysis@jkohjkng.top"; //发送方邮箱
    private static final String FROM_PSW = "pKOPP4hfcFI5qW4i";//发送方邮箱授权码

    public static void send(MailInfo info) {
        final MailInfo mailInfo = createMail(info);
        final MailSender sms = new MailSender();
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (mailInfo.getAttachFile() != null) {
                    sms.sendFileMail(mailInfo, mailInfo.getAttachFile());
                } else {
                    sms.sendTextMail(mailInfo);
                }
            }
        }).start();
    }

    private static MailInfo createMail(MailInfo info) {
        final MailInfo mailInfo = new MailInfo();
        if (info != null) {
            mailInfo.setMailServerHost(info.getMailServerHost() != null ? info.getMailServerHost() : HOST);
            mailInfo.setMailServerPort(info.getMailServerPort() != null ? info.getMailServerPort() : PORT);
            mailInfo.setValidate(true);
            mailInfo.setUserName(info.getUserName() != null ? info.getUserName() : FROM_USER); // 你的邮箱地址
            mailInfo.setPassword(info.getPassword() != null ? info.getPassword() : FROM_PSW);// 您的邮箱密码
            mailInfo.setFromAddress(info.getFromAddress() != null ? info.getFromAddress() : FROM_ADD); // 发送的邮箱
            mailInfo.setToAddress(info.getToAddress()); // 发到哪些邮件去
            mailInfo.setSubject(info.getSubject()); // 邮件主题
            mailInfo.setContent(info.getContent()); // 邮件文本
            mailInfo.setAttachFile(info.getAttachFile());
        }
        return mailInfo;
    }
}